/*eslint-disable*/
// 选择题

const {
    getById,    // 根据id获取题数据
    getList,    // 获取题列表
    create,     // 添加题
    edit,       // 编辑题
    remove,     // 删除题
} = require('../../service/question/question');

exports.questionApi = async ctx => { 
    // 获取url 字段 继而判断接下来操作
    let url = ctx.request.url.split('/');
    let urlKey = url[2].split('?')[0];
    const { id } = ctx.params || '';
    const { pageNum, pageSize } = ctx.query || '';
    const { title, options, chapter_id, answer, creator, updator, usage, difficulty, type_id, analysis, catalouge_id } = ctx.request.body || '';
    let res;
    switch (ctx.request.method) {
        case 'GET': if (urlKey == 'byid') {
            res = await getById({ id });
        } else {
            if (urlKey == 'list') {
                res = await getList({ pageNum, pageSize, type_id, title });
            }
        } break;
        case 'POST': res = await create({ catalouge_id, title, chapter_id, options, answer, creator, usage, difficulty, type_id, analysis }); break;
        case 'DELETE': res = await remove({ id }); break;
        case 'PUT': res = await edit({ catalouge_id, id, title,type_id, chapter_id, options, answer, creator, updator, usage, difficulty, analysis }); break;
        default: res = { msg: '操作失败 请求方法不规范', code: '400' };
    }
    ctx.body = res;
};